package com.gossip;

import java.nio.ByteBuffer;

public class GossipFile {
	
	private byte[] _fileBytes;
	private String _fileName;
	private int _minSizeContent = 128;
	private String _path;
	
	public GossipFile()
	{}
	
	public void loadFile(byte[] fileContents)
	{
		setFile(fileContents);
	}
	
	private void saveFile()
	{
		String filePath = _path + _fileName;
	}
	
	private Boolean setFile(byte[] fileContents)
	{
		if(fileContents==null||fileContents.length<_minSizeContent)
			return false;
		ByteBuffer bb = ByteBuffer.wrap(new byte[] {fileContents[0], fileContents[1], fileContents[2], fileContents[3]});
		int nameLength = bb.getInt();
		byte[] nameBytes = new byte[nameLength];
		for(int i = 0;i<nameLength;i++)
		{
			nameBytes[i] = fileContents[i+4];
		}
		_fileName = new String(nameBytes);
		_fileBytes = new byte[fileContents.length-nameLength-4];
		for(int i=0;i<_fileBytes.length;i++)
		{
			_fileBytes[i] = fileContents[i+4+nameLength];
		}
		return true;
	}

}
